﻿@using System.ComponentModel.DataAnnotations;
@using System.Text.Json;
@using System.ComponentModel

<!-- TODO: Make work with validation visuals. Submission will work though. -->
<AntDesign.Form Model="@model"
        OnFinish="OnFinish"
        OnFinishFailed="OnFinishFailed"
        LabelColSpan="8"
        WrapperColSpan="16">
    <FormItem Label="Comment">
        <Mentions @bind-Value=@model.Comment>
            <MentionsOption Value="afc163">afc163</MentionsOption>
            <MentionsOption Value="zombieJ">zombieJ</MentionsOption>
            <MentionsOption Value="yesmeck">yesmeck</MentionsOption>
        </Mentions>
    </FormItem>
    <FormItem Label="Another Comment">
        <Mentions @bind-Value=@model.AnotherComment>
            <ChildContent>
                <MentionsOption Value="afc163">afc163</MentionsOption>
                <MentionsOption Value="zombieJ">zombieJ</MentionsOption>
                <MentionsOption Value="yesmeck">yesmeck</MentionsOption>
            </ChildContent>
            <TextareaTemplate Context="mentionsContext">
                <TextArea RefBack=@mentionsContext.RefBack
                          OnInput=@mentionsContext.OnInput
                          BindOnInput=false
                          OnkeyDown=@mentionsContext.OnKeyDown
                          Value=@mentionsContext.Value
                          ShowCount=true
                          MaxLength="200" />
            </TextareaTemplate>
        </Mentions>
    </FormItem>
    <FormItem WrapperColOffset="8" WrapperColSpan="16">
        <Button Type="@ButtonType.Primary" HtmlType="submit">
            Submit
        </Button>
    </FormItem>
</AntDesign.Form>
@code
{
    public class Model
    {
        [Required]
        public string Comment { get; set; }

        [Required]
        public string AnotherComment{ get; set; }
    }

    private Model model = new Model();

    private void OnFinish(EditContext editContext)
    {
        Console.WriteLine($"Success:{JsonSerializer.Serialize(model)}");
    }

    private void OnFinishFailed(EditContext editContext)
    {
        Console.WriteLine($"Failed:{JsonSerializer.Serialize(model)}");
    }
}